<?php

namespace App\Http\Validate\Invoice;

use App\Http\Validate\AbstractBaseValidate;
use App\Models\Invoice\InvoiceHeadModel;
use Illuminate\Support\MessageBag;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class InvoiceHeaderValidate extends AbstractBaseValidate
{
    function getRules(): array
    {
        // TODO: Implement getRules() method.
        return [];
    }

    function getAttributes(): array
    {
        // TODO: Implement getAttributes() method.
        return [];
    }

    function registerValidateRules(): void
    {
        // TODO: Implement registerValidateRules() method.
    }

    function getMessages(): array
    {
        // TODO: Implement getMessages() method.
        return [];
    }


    /** 公共验证
     * @return MessageBag|object
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function updateValidate(array $params)
    {
        return self::getInstance()->validate(
            ['id', "headerType", "invoiceType", 'email', 'mobile'],
            $params,
            [
                'id'          => [
                    "required",
                    "int",
                    Rule::exists((new InvoiceHeadModel())->getTable(), "id")
                ],
                "headerType"  => "required|int",
                "invoiceType" => "required|int",
                'email'       => 'email',
                'mobile'      => "int",
            ]
        );
    }


    /** 企业普通发票验证
     * @return MessageBag|object
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function updateCommonValidate(array $params)
    {
        return self::getInstance()->validate(
            ['id', "headerType", "invoiceType", "invoiceTitle", 'companyTaxNumber'],
            $params,
            [
                'id'               => [
                    "required",
                    "int",
                    Rule::exists((new InvoiceHeadModel())->getTable(), "id")
                ],
                "headerType"       => "required|int",
                "invoiceType"      => "required|int",
                "invoiceTitle"     => "required|string",
                "companyTaxNumber" => "required|string"
            ]
        );
    }

    /** 企业专用发票验证
     * @return MessageBag|object
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function updateSpecialValidate(array $params)
    {
        return self::getInstance()->validate(
            [
                'id',
                "headerType",
                "invoiceType",
                "invoiceTitle",
                "companyTaxNumber",
                'companyRegisterAddress',
                'companyRegisterMobile',
                'companyDepositBank',
                'companyDepositBankNum'
            ],
            $params,
            [
                'id'                     => [
                    "required",
                    "int",
                    Rule::exists((new InvoiceHeadModel())->getTable(), "id")
                ],
                "headerType"             => "required|int",
                "invoiceType"            => "required|int",
                "invoiceTitle"           => "required|string",
                "companyTaxNumber"       => "required|string",
                "companyRegisterAddress" => "required|string",
                "companyRegisterMobile"  => "required|string",
                "companyDepositBank"     => "required|string",
                "companyDepositBankNum"  => "required|string"
            ]
        );
    }


}
